var ACTION = require("../../base/action");
var utils = require("../../newUtils/utils");
var time = require("../../newUtils/time");
var ocrGml = require("../../newUtils/ocrGml");
var common = require("../common");
var walkAction = new ACTION("走路");

walkAction.goStart = function () {
  if (common.inHome()) {
    sleep(utils.getRandom(1.5, 2, 1000));
    common.toTask();
    sleep(utils.getRandom(1.5, 2, 1000));
    var ocrItem = ocrGml.captureExistOne("走路赚钱");
    console.log(this.name, "goStart", (ocrItem ? "" : "没") + "找到-走路赚钱-");
    if (ocrItem) {
      utils.clickOcrItem(ocrItem);
    }
    sleep(utils.getRandom(1.5, 2, 1000));
    return ocrItem;
  }
};
walkAction.beforeExec = function () {
  var UIText = utils.existsTextMatches(/领取\d+金币/);
  console.log((UIText ? "" : "没") + "找到-领取d+金币-");
  return UIText;
};
walkAction.exec = function (UIText) {
  utils.clickUIText(UIText);
  sleep(utils.getRandom(2, 3, 1000));
  var contents = [
    //prettier-ignore
    "看视频再",
    "看广告再",
  ];
  var UIText = utils.existsOneTextStartsWith(contents);
  if (UIText) {
    console.log("找到-" + UIText.text() + "-");
    utils.clickUIText(UIText);
    sleep(utils.getRandom(2, 3, 1000));
    common.ad.init(1, function () {
      var ocrItem = ocrGml.captureExistOne([
        "走路奖励",
        "今日步数",
        "活动说明",
      ]);
      console.log("找到-" + ocrItem.text + "-");
      return ocrItem;
    });
    return;
  }
  var contents = [
    //prettier-ignore
    "开心收下",
    "立即收下",
  ];
  var UIText = utils.existsOneTextStartsWith(contents);
  if (UIText) {
    console.log("找到-" + UIText.text() + "-");
    utils.clickUIText(UIText);
    return;
  }
};
walkAction.afterExec = function () {
  console.log(this.name, time.str(), "afterExec");
  sleep(utils.getRandom(1.5, 2, 1000));
  back();
};
module.exports = walkAction;
